import type { FormSchemaGetter } from '#/adapter/form';
import type { VxeGridProps } from '#/adapter/vxe-table';

import { subscribeselect } from '#/api/iot/relay/consumerGroup';

export const querySchema: FormSchemaGetter = () => [
  {
    component: 'Input',
    fieldName: 'groupName',
    label: '消费组名称',
  },
];

export const columns: VxeGridProps['columns'] = [
  {
    title: '序号',
    type: 'seq',
    width: 100,
  },
  {
    title: '消费组名称',
    field: 'groupName',
    showOverflow: true,
  },
  {
    title: '消费组ID',
    field: 'groupIdentifier',
  },
  {
    title: '创建时间',
    field: 'createTime',
  },
  {
    field: 'action',
    fixed: 'right',
    slots: { default: 'action' },
    title: '操作',
    resizable: false,
    width: 'auto',
  },
];

export const drawerSchema: FormSchemaGetter = () => [
  {
    label: 'id',
    fieldName: 'id',
    component: 'Input',
    dependencies: {
      show: () => false,
      triggerFields: [''],
    },
  },
  {
    component: 'Input',
    fieldName: 'groupName',
    label: '消费组名称',
    rules: 'required',
  },
  {
    component: 'ApiSelect',
    fieldName: 'subscribeIds',
    label: '订阅',
    rules: 'selectRequired',
    componentProps: {
      filterOption: true,
      showSearch: true,
      mode: 'multiple',
      api: subscribeselect,
      optionFilterProp: 'productName',
      allowClear: true,
      fieldNames: {
        label: 'productName',
        value: 'id',
      },
    },
  },
];
